using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Norah
{
	/// <summary>
	/// GameState
	/// </summary>
	public enum GameState
	{
		GameScreen,
		MainMenu,
		OptionMenu,
		PauseMenu
	}

	/// <summary>
	/// InGameState
	/// </summary>
	public enum InGameState
	{
		Paused,
		Playing
	}

	/// <summary>
	/// This is the main type for your game
	/// </summary>
	public class Game1 : Microsoft.Xna.Framework.Game
	{
		GraphicsDeviceManager graphics;
		SpriteBatch spriteBatch;

		private GameState m_currentGameState;
		private InGameState	m_currentInGameState;

		private static int m_frameCounter = 0;
		private static int m_frameRate = 0;
		private float m_elapsedTime = 0.00f;

		public Game1()
		{
			graphics = new GraphicsDeviceManager(this);
			m_currentGameState = GameState.MainMenu;
			m_currentInGameState = InGameState.Paused;
			Content.RootDirectory = "Content";
		}
	
		/// <summary>
		/// Allows the game to perform any initialization it needs to before starting to run.
		/// This is where it can query for any required services and load any non-graphic
		/// related content.  Calling base.Initialize will enumerate through any components
		/// and initialize them as well.
		/// </summary>
		protected override void Initialize()
		{
			// TODO: Add your initialization logic here

			base.Initialize();
		}

		/// <summary>
		/// LoadContent will be called once per game and is the place to load
		/// all of your content.
		/// </summary>
		protected override void LoadContent()
		{
			// Create a new SpriteBatch, which can be used to draw textures.
			spriteBatch = new SpriteBatch(GraphicsDevice);

			// TODO: use this.Content to load your game content here
		}

		/// <summary>
		/// UnloadContent will be called once per game and is the place to unload
		/// all content.
		/// </summary>
		protected override void UnloadContent()
		{
			// TODO: Unload any non ContentManager content here
		}

		/// <summary>
		/// Allows the game to run logic such as updating the world,
		/// checking for collisions, gathering input, and playing audio.
		/// </summary>
		/// <param name="gameTime">Provides a snapshot of timing values.</param>
		protected override void Update(GameTime gameTime)
		{
			// TODO: Add your update logic here
			switch (m_currentGameState)
			{
				case GameState.GameScreen:
				{
					if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
					{
						m_currentGameState = GameState.MainMenu;
						break;
					}

					switch (m_currentInGameState)
					{
						case InGameState.Playing:
						{
							break;
						}
						case InGameState.Paused:
						{
 							break;
						}
					}

					break;
				}
				case GameState.MainMenu:
				{
					if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
						this.Exit();
					/*
					else if (start.Selected)
						m_currentGameState = GameState.GameScreen;
					else if (load.Selected)
						m_currentGameState = GameState.GameScreen;
					else if (options.Selected)
						m_currentGameState = GameState.OptionMenu;
					else if (quit.Selected)
						this.Exit();
					*/
					break;
				}
				case GameState.OptionMenu:
				{
					break;
				}
				case GameState.PauseMenu:
				{
					break;
				}
			}

			base.Update(gameTime);
		}

		/// <summary>
		/// This is called when the game should draw itself.
		/// </summary>
		/// <param name="gameTime">Provides a snapshot of timing values.</param>
		protected override void Draw(GameTime gameTime)
		{
			GraphicsDevice.Clear(Color.CornflowerBlue);

			// TODO: Add your drawing code here
			switch (m_currentGameState)
			{
 				case GameState.GameScreen:
				{
					break;
				}
				case GameState.MainMenu:
				{
					break;
				}
				case GameState.OptionMenu:
				{
					break;
				}
				case GameState.PauseMenu:
				{
					break;
				}
			}

			this.UpdateFrameRate(gameTime);
			base.Draw(gameTime);
		}

		private void UpdateFrameRate(GameTime gameTime)
		{
			m_elapsedTime += gameTime.ElapsedGameTime.Milliseconds;
			m_frameCounter++;

			if (m_elapsedTime >= 1000.0f)
			{
				m_elapsedTime -= 1000.0f;
				m_frameRate = m_frameCounter;
				m_frameCounter = 0;
			}

		}

	}
}
